package com.chandra.pos.convertor;

/* @(#) AbstractMapperListConverter.java
 * Copyright 2013 - 2015 QatarAirways Group. All Rights Reserved.
 *
 * This Software is the proprietary information of QR Group
 * Use is subject to License terms.
 * Created by T4671 on 18/03/2015.
 */

import org.dozer.Mapper;
import org.springframework.util.Assert;


public class AbstractMapperListConverter<T, V> extends AbstractListConverter<T, V> {

    private final Mapper mapper;
    private final Class<T> tClazz;
    private final Class<V> vClazz;

    public AbstractMapperListConverter(Mapper mapper,
                                       Class<T> tClazz, Class<V> vClazz) {
        this.mapper = mapper;
        this.tClazz = tClazz;
        this.vClazz = vClazz;
    }

    @Override
    public V convertTo(T source) {
        Assert.notNull(source, "Source must not be null.");

        return mapper.map(source, vClazz);
    }

    @Override
    public T convertFrom(V source) {
        Assert.notNull(source, "Source must not be null.");

        return mapper.map(source, tClazz);
    }
}
